
//
// test the endianess.hpp
//

#include <iostream>
#include <string>
#include <cassert>

using namespace std;

#include <endianess.hpp>

template<typename Integer>
void test_byteorder_cast(Integer n)
{

	Integer host = n;
	Integer network = kb::to_byteorder_cast<kb::network_byteorder>(n);

	cout << "host: " << hex << host << endl;
	cout << "network: " << hex << network << endl;

	assert(host == kb::ntoh(network));
	assert((kb::byteorder_cast<kb::little_endian, kb::little_endian>(n) == host));
	assert((kb::byteorder_cast<kb::little_endian, kb::big_endian>(n) == network));
	assert((kb::byteorder_cast<kb::big_endian, kb::big_endian>(n) == host));
	assert((kb::byteorder_cast<kb::big_endian, kb::little_endian>(n) == network));

	assert((kb::byteorder_cast<kb::network_byteorder, kb::host_byteorder>(n) == network));
	assert((kb::byteorder_cast<kb::network_byteorder, kb::network_byteorder>(n) == host));
	assert((kb::byteorder_cast<kb::host_byteorder, kb::network_byteorder>(n) == network));
	assert((kb::byteorder_cast<kb::host_byteorder, kb::host_byteorder>(n) == host));
}

int main(int argc, char**argv) {

	unsigned long long n_ull = 0x1234567890abcdefULL;
	test_byteorder_cast(n_ull);
	int n = 0x12345678L;
	test_byteorder_cast(n);

	return 0;
}
